﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:System="clr-namespace:System;assembly=mscorlib">

  <!--ACCENT COLORS-
  <Color x:Key="HighlightColor">#FF086F9E</Color -->

  <!-- 80%-->
  <Color x:Key="AccentColor">#CC119EDA</Color>
  <!--60%-->
  <!-- Color x:Key="AccentColor2">#99119EDA</Color>
  -40%-
  <Color x:Key="AccentColor3">#66119EDA</Color>
  -20%-
  <Color x:Key="AccentColor4">#33119EDA</Color -->

  <!-- re-set brushes too 
  <SolidColorBrush x:Key="HighlightBrush" Color="{StaticResource HighlightColor}" />
  <SolidColorBrush x:Key="AccentColorBrush" Color="{StaticResource AccentColor}"/>
  <SolidColorBrush x:Key="AccentColorBrush2" Color="{StaticResource AccentColor2}"/>
  <SolidColorBrush x:Key="AccentColorBrush3" Color="{StaticResource AccentColor3}"/>
  <SolidColorBrush x:Key="AccentColorBrush4" Color="{StaticResource AccentColor4}"/ -->

  <!-- SolidColorBrush x:Key="WindowTitleColorBrush" Color="{StaticResource AccentColor}" / -->

  <!-- SolidColorBrush x:Key="AccentSelectedColorBrush" Color="White" / -->

  <!-- LinearGradientBrush x:Key="ProgressBrush" EndPoint="0.001,0.5" StartPoint="1.002,0.5">
    <GradientStop Color="{StaticResource HighlightColor}" Offset="0" />
    <GradientStop Color="{StaticResource AccentColor3}" Offset="1" />
  </LinearGradientBrush -->

  <SolidColorBrush x:Key="CheckmarkFill" Color="{StaticResource AccentColor}" />
  <SolidColorBrush x:Key="RightArrowFill" Color="{StaticResource AccentColor}" />

  <Color x:Key="BlackColor">#FFFFFFFF</Color>
  <Color x:Key="WhiteColor">#FF252525</Color>

  <Color x:Key="Gray1">#FFF9F9F9</Color>
  <Color x:Key="Gray2">#FF7F7F7F</Color>
  <Color x:Key="Gray7">#FF7E7E7E</Color>
  <Color x:Key="Gray8">#FF454545</Color>
  <Color x:Key="Gray10">#FF2F2F2F</Color>

  <!-- Color x:Key="GrayNormal">#FF7D7D7D</Color -->
  <!-- Color x:Key="GrayHover">#FFAAAAAA</Color -->

  <Color x:Key="FlyoutBackgroundColor">#2B2B2B</Color>

  <!-- re-set brushes too -->
  <SolidColorBrush x:Key="BlackBrush" Color="{StaticResource BlackColor}" />
  <SolidColorBrush x:Key="TextBrush" Color="{StaticResource BlackColor}" />
  <SolidColorBrush x:Key="LabelTextBrush" Color="{StaticResource BlackColor}" />
  <SolidColorBrush x:Key="BlackColorBrush" Color="{StaticResource BlackColor}" />
  <SolidColorBrush x:Key="TextBoxMouseOverInnerBorderBrush" Color="{StaticResource BlackColor}" />
  <SolidColorBrush x:Key="TextBoxFocusBorderBrush" Color="{StaticResource BlackColor}" />
  <SolidColorBrush x:Key="ButtonMouseOverBorderBrush" Color="{StaticResource BlackColor}" />
  <SolidColorBrush x:Key="ButtonMouseOverInnerBorderBrush" Color="{StaticResource BlackColor}" />
  <SolidColorBrush x:Key="ComboBoxMouseOverBorderBrush" Color="{StaticResource BlackColor}" />
  <SolidColorBrush x:Key="ComboBoxMouseOverInnerBorderBrush" Color="{StaticResource BlackColor}" />

  <SolidColorBrush x:Key="ControlBackgroundBrush" Color="{StaticResource WhiteColor}" />
  <SolidColorBrush x:Key="WhiteBrush" Color="{StaticResource WhiteColor}" />
  <SolidColorBrush x:Key="WhiteColorBrush" Color="{StaticResource WhiteColor}" />
  <SolidColorBrush x:Key="DisabledWhiteBrush" Color="{StaticResource WhiteColor}" />
  <SolidColorBrush x:Key="WindowBackgroundBrush" Color="{StaticResource WhiteColor}" />

  <SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="{StaticResource WhiteColor}" />
  <SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="{StaticResource BlackColor}" />

  <LinearGradientBrush x:Key="CheckBoxBackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0">
    <GradientStop Color="{StaticResource Gray7}" Offset="0" />
    <GradientStop Color="{StaticResource WhiteColor}" Offset="1" />
  </LinearGradientBrush>

  <!-- SolidColorBrush x:Key="GrayBrush1" Color="{StaticResource Gray1}" />
  <SolidColorBrush x:Key="GrayBrush2" Color="{DynamicResource Gray2}"/>
  <SolidColorBrush x:Key="GrayBrush7" Color="{StaticResource Gray7}" />
  <SolidColorBrush x:Key="GrayBrush8" Color="{StaticResource Gray8}" />
  <SolidColorBrush x:Key="GrayBrush10" Color="{StaticResource Gray10}" / -->

  <!-- SolidColorBrush x:Key="GrayNormalBrush" Color="{StaticResource GrayNormal}" / -->
  <!-- SolidColorBrush x:Key="GrayHoverBrush" Color="{StaticResource GrayHover}" / -->

  <!-- SolidColorBrush x:Key="CheckBoxMouseOverBrush" Color="{StaticResource Gray1}" / -->

  <!-- SolidColorBrush x:Key="SliderValueDisabled" Color="#FF535353" / -->
  <!-- SolidColorBrush x:Key="SliderTrackDisabled" Color="#FF383838" / -->
  <!-- SolidColorBrush x:Key="SliderThumbDisabled" Color="#FF7E7E7E" / -->
  <!-- SolidColorBrush x:Key="SliderTrackHover" Color="#FF737373" / -->
  <!-- SolidColorBrush x:Key="SliderTrackNormal" Color="#FF6C6C6C" / -->

  <!-- SolidColorBrush x:Key="FlyoutBackgroundBrush" Color="{StaticResource FlyoutBackgroundColor}" / -->

  <SolidColorBrush x:Key="FlatButtonPressedBackgroundBrush" Color="#444444"/>

  <!-- menu brushes -->
  <SolidColorBrush x:Key="MenuBackgroundBrush" Color="{StaticResource WhiteColor}" />
  <SolidColorBrush x:Key="ContextMenuBackgroundBrush" Color="{StaticResource WhiteColor}" />
  <SolidColorBrush x:Key="SubMenuBackgroundBrush" Color="{StaticResource WhiteColor}" />

  <SolidColorBrush x:Key="ContextMenuBorderBrush" Color="{StaticResource BlackColor}" />
  <SolidColorBrush x:Key="SubMenuBorderBrush" Color="{StaticResource BlackColor}" />

  <SolidColorBrush x:Key="MenuItemSelectionFill" Color="#313131" />
  <SolidColorBrush x:Key="MenuItemSelectionStroke" Color="#313131" />

  <SolidColorBrush x:Key="TopMenuItemPressedFill" Color="#313131" />
  <SolidColorBrush x:Key="TopMenuItemPressedStroke" Color="#E0717070" />
  <SolidColorBrush x:Key="TopMenuItemSelectionStroke" Color="#90717070" />

  <!-- original #FF9A9A9A" -->
  <SolidColorBrush x:Key="DisabledMenuItemForeground" Color="{StaticResource Gray7}" />
  <SolidColorBrush x:Key="DisabledMenuItemGlyphPanel" Color="#848589" />

  <SolidColorBrush x:Key="{x:Static SystemColors.MenuTextBrushKey}" Color="{StaticResource BlackColor}" />

  <Color x:Key="MenuShadowColor">#FFFFFFFF</Color>

  <MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter" />

  <Geometry x:Key="Checkmark">M 0,5.1 L 1.7,5.2 L 3.4,7.1 L 8,0.4 L 9.2,0 L 3.3,10.8 Z</Geometry>
  <Geometry x:Key="RightArrow">M 0,0 L 4,3.5 L 0,7 Z</Geometry>
  <Geometry x:Key="DownArrow">M 0,0 L 3.5,4 L 7,0 Z</Geometry>
  <Geometry x:Key="UpArrow">M 0,4 L 3.5,0 L 7,4 Z</Geometry>

  <Style x:Key="{x:Static MenuItem.SeparatorStyleKey}"
           TargetType="{x:Type Separator}">
    <Setter Property="Background"
                Value="{DynamicResource MenuBackgroundBrush}" />
    <Setter Property="IsTabStop"
                Value="False" />
    <Setter Property="Margin"
                Value="6,2,6,2" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Separator}">
          <Grid Margin="0,6,0,4"
                          SnapsToDevicePixels="true">
            <Rectangle Fill="#E0E0E0"
                                   Height="1"
                                   Margin="20,0,1,1" />
            <Rectangle Fill="White"
                                   Height="1"
                                   Margin="20,1,1,0" />
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="MetroMenu"
           TargetType="{x:Type Menu}">
    <Setter Property="SnapsToDevicePixels"
                Value="True" />
    <Setter Property="RenderOptions.ClearTypeHint"
                Value="Enabled" />
    <Setter Property="TextOptions.TextFormattingMode"
                Value="Ideal" />
    <Setter Property="Background"
                Value="{DynamicResource MenuBackgroundBrush}" />
    <Setter Property="FontFamily"
                Value="{DynamicResource {x:Static SystemFonts.MenuFontFamilyKey}}" />
    <Setter Property="FontSize"
                Value="{DynamicResource MenuFontSize}" />
    <Setter Property="FontStyle"
                Value="{DynamicResource {x:Static SystemFonts.MenuFontStyleKey}}" />
    <Setter Property="FontWeight"
                Value="{DynamicResource {x:Static SystemFonts.MenuFontWeightKey}}" />
    <Setter Property="Foreground"
                Value="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Menu}">
          <Border BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Background="{TemplateBinding Background}"
                            Padding="{TemplateBinding Padding}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <ItemsPresenter Margin="0"
                                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="MetroContextMenu"
           TargetType="{x:Type ContextMenu}">
    <Setter Property="SnapsToDevicePixels"
                Value="True" />
    <Setter Property="RenderOptions.ClearTypeHint"
                Value="Enabled" />
    <Setter Property="TextOptions.TextFormattingMode"
                Value="Ideal" />
    <Setter Property="Background"
                Value="{DynamicResource ContextMenuBackgroundBrush}" />
    <Setter Property="BorderThickness"
                Value="1" />
    <Setter Property="BorderBrush"
                Value="{DynamicResource ContextMenuBorderBrush}" />
    <Setter Property="OverridesDefaultStyle"
                Value="True" />
    <Setter Property="Grid.IsSharedSizeScope"
                Value="True" />
    <Setter Property="HasDropShadow"
                Value="True" />
    <Setter Property="FontFamily"
                Value="{DynamicResource {x:Static SystemFonts.MenuFontFamilyKey}}" />
    <Setter Property="FontSize"
                Value="{DynamicResource ContextMenuFontSize}" />
    <Setter Property="FontStyle"
                Value="{DynamicResource {x:Static SystemFonts.MenuFontStyleKey}}" />
    <Setter Property="FontWeight"
                Value="{DynamicResource {x:Static SystemFonts.MenuFontWeightKey}}" />
    <Setter Property="Foreground"
                Value="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ContextMenu}">
          <Border x:Name="LayoutRoot"
                            Background="Transparent">
            <Border x:Name="Border"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Background="{TemplateBinding Background}"
                                Padding="{TemplateBinding Padding}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">

              <ScrollViewer x:Name="SubMenuScrollViewer"
                                          CanContentScroll="True"
                                          Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                <ItemsPresenter x:Name="ItemsPresenter"
                                                KeyboardNavigation.DirectionalNavigation="Cycle"
                                                Grid.IsSharedSizeScope="True"
                                                Margin="0"
                                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                                KeyboardNavigation.TabNavigation="Cycle" />
              </ScrollViewer>
            </Border>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="HasDropShadow"
                                 Value="True">
              <Setter TargetName="LayoutRoot"
                                    Property="Effect">
                <Setter.Value>
                  <DropShadowEffect Color="{DynamicResource MenuShadowColor}"
                                                      BlurRadius="4"
                                                      ShadowDepth="2"
                                                      Direction="315"
                                                      Opacity="0.3" />
                </Setter.Value>
              </Setter>
              <Setter TargetName="LayoutRoot"
                                    Property="Padding"
                                    Value="0,0,6,6" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="MetroMenuItem"
           TargetType="{x:Type MenuItem}">
    <Setter Property="HorizontalContentAlignment"
                Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
    <Setter Property="VerticalContentAlignment"
                Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
    <Setter Property="Background"
                Value="Transparent" />
    <Setter Property="ScrollViewer.PanningMode"
                Value="Both" />
    <Setter Property="Stylus.IsFlicksEnabled"
                Value="False" />
    <Setter Property="Template"
                Value="{DynamicResource {ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
    <Style.Triggers>
      <Trigger Property="Role"
                     Value="TopLevelHeader">
        <Setter Property="Padding"
                        Value="7,5,8,6" />
        <Setter Property="Template"
                        Value="{DynamicResource {ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
      </Trigger>
      <Trigger Property="Role"
                     Value="TopLevelItem">
        <Setter Property="Padding"
                        Value="7,5,8,6" />
        <Setter Property="Template"
                        Value="{DynamicResource {ComponentResourceKey ResourceId=TopLevelItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
      </Trigger>
      <Trigger Property="Role"
                     Value="SubmenuHeader">
        <Setter Property="Padding"
                        Value="2,6,2,6" />
        <Setter Property="Template"
                        Value="{DynamicResource {ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
      </Trigger>
      <Trigger Property="Role"
                     Value="SubmenuItem">
        <Setter Property="Padding"
                        Value="2,6,2,6" />
      </Trigger>
    </Style.Triggers>
  </Style>

  <ContextMenu x:Key="TextBoxMetroContextMenu" Style="{StaticResource MetroContextMenu}">
    <MenuItem Command="ApplicationCommands.Cut"
                  Style="{DynamicResource MetroMenuItem}" />
    <MenuItem Command="ApplicationCommands.Copy"
                  Style="{DynamicResource MetroMenuItem}" />
    <MenuItem Command="ApplicationCommands.Paste"
                  Style="{DynamicResource MetroMenuItem}" />
  </ContextMenu>

  <Style x:Key="MenuScrollButton"
           BasedOn="{x:Null}"
           TargetType="{x:Type RepeatButton}">
    <Setter Property="ClickMode"
                Value="Hover" />
    <Setter Property="MinWidth"
                Value="0" />
    <Setter Property="MinHeight"
                Value="0" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type RepeatButton}">
          <DockPanel Background="Transparent"
                               SnapsToDevicePixels="True">
            <Rectangle x:Name="R1"
                                   DockPanel.Dock="Right"
                                   Fill="Transparent"
                                   Width="1" />
            <Rectangle x:Name="B1"
                                   DockPanel.Dock="Bottom"
                                   Fill="Transparent"
                                   Height="1" />
            <Rectangle x:Name="L1"
                                   DockPanel.Dock="Left"
                                   Fill="Transparent"
                                   Width="1" />
            <Rectangle x:Name="T1"
                                   DockPanel.Dock="Top"
                                   Fill="Transparent"
                                   Height="1" />
            <ContentPresenter x:Name="ContentContainer"
                                          HorizontalAlignment="Center"
                                          Margin="6"
                                          VerticalAlignment="Center" />
          </DockPanel>
          <ControlTemplate.Triggers>
            <Trigger Property="IsPressed"
                                 Value="True">
              <Setter Property="Fill"
                                    TargetName="R1"
                                    Value="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}" />
              <Setter Property="Fill"
                                    TargetName="B1"
                                    Value="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}" />
              <Setter Property="Fill"
                                    TargetName="L1"
                                    Value="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" />
              <Setter Property="Fill"
                                    TargetName="T1"
                                    Value="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="{ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}"
           BasedOn="{x:Null}"
           TargetType="{x:Type ScrollViewer}">
    <Setter Property="HorizontalScrollBarVisibility"
                Value="Hidden" />
    <Setter Property="VerticalScrollBarVisibility"
                Value="Auto" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ScrollViewer}">
          <Grid SnapsToDevicePixels="True">
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto" />
              <RowDefinition Height="*" />
              <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Border Grid.Column="0"
                                Grid.Row="1">
              <ScrollContentPresenter Margin="{TemplateBinding Padding}" />
            </Border>
            <RepeatButton Grid.Column="0"
                                      CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                      Command="{x:Static ScrollBar.LineUpCommand}"
                                      Focusable="False"
                                      Grid.Row="0"
                                      Style="{StaticResource MenuScrollButton}">
              <RepeatButton.Visibility>
                <MultiBinding ConverterParameter="0"
                                              Converter="{StaticResource MenuScrollingVisibilityConverter}"
                                              FallbackValue="Visibility.Collapsed">
                  <Binding Path="ComputedVerticalScrollBarVisibility"
                                             RelativeSource="{RelativeSource TemplatedParent}" />
                  <Binding Path="VerticalOffset"
                                             RelativeSource="{RelativeSource TemplatedParent}" />
                  <Binding Path="ExtentHeight"
                                             RelativeSource="{RelativeSource TemplatedParent}" />
                  <Binding Path="ViewportHeight"
                                             RelativeSource="{RelativeSource TemplatedParent}" />
                </MultiBinding>
              </RepeatButton.Visibility>
              <Path Data="{StaticResource UpArrow}"
                                  Fill="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" />
            </RepeatButton>
            <RepeatButton Grid.Column="0"
                                      CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                      Command="{x:Static ScrollBar.LineDownCommand}"
                                      Focusable="False"
                                      Grid.Row="2"
                                      Style="{StaticResource MenuScrollButton}">
              <RepeatButton.Visibility>
                <MultiBinding ConverterParameter="100"
                                              Converter="{StaticResource MenuScrollingVisibilityConverter}"
                                              FallbackValue="Visibility.Collapsed">
                  <Binding Path="ComputedVerticalScrollBarVisibility"
                                             RelativeSource="{RelativeSource TemplatedParent}" />
                  <Binding Path="VerticalOffset"
                                             RelativeSource="{RelativeSource TemplatedParent}" />
                  <Binding Path="ExtentHeight"
                                             RelativeSource="{RelativeSource TemplatedParent}" />
                  <Binding Path="ViewportHeight"
                                             RelativeSource="{RelativeSource TemplatedParent}" />
                </MultiBinding>
              </RepeatButton.Visibility>
              <Path Data="{StaticResource DownArrow}"
                                  Fill="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" />
            </RepeatButton>
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}"
                     TargetType="{x:Type ContentControl}">
    <Border BorderBrush="{DynamicResource SubMenuBorderBrush}"
                BorderThickness="1"
                Background="{DynamicResource SubMenuBackgroundBrush}">
      <ContentPresenter />
    </Border>
  </ControlTemplate>

  <ControlTemplate x:Key="{ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}"
                     TargetType="{x:Type MenuItem}">
    <Grid SnapsToDevicePixels="True">
      <Rectangle x:Name="Bg"
                       Fill="{TemplateBinding Background}"
                       Margin="1"
                       Stroke="{TemplateBinding BorderBrush}"
                       StrokeThickness="1" />
      <DockPanel>
        <ContentPresenter x:Name="Icon"
                                  ContentSource="Icon"
                                  Margin="4,0,6,0"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                  VerticalAlignment="Center" />
        <Path x:Name="GlyphPanel"
                      Data="{StaticResource Checkmark}"
                      Fill="{DynamicResource CheckmarkFill}"
                      FlowDirection="LeftToRight"
                      Visibility="Collapsed"
                      Margin="8,0,0,0"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center" />
        <ContentPresenter ContentSource="Header"
                                  Margin="{TemplateBinding Padding}"
                                  RecognizesAccessKey="True"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
      </DockPanel>
      <Popup x:Name="PART_Popup"
                   AllowsTransparency="True"
                   Focusable="False"
                   HorizontalOffset="1"
                   IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
                   PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
                   Placement="Bottom"
                   VerticalOffset="-1">
        <Border x:Name="LayoutRoot"
                        Background="Transparent">
          <ContentControl x:Name="SubMenuBorder"
                                    IsTabStop="False"
                                    Template="{DynamicResource {ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}}">
            <ScrollViewer x:Name="SubMenuScrollViewer"
                                      CanContentScroll="True"
                                      Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
              <ItemsPresenter x:Name="ItemsPresenter"
                                            KeyboardNavigation.DirectionalNavigation="Cycle"
                                            Grid.IsSharedSizeScope="True"
                                            Margin="0"
                                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                            KeyboardNavigation.TabNavigation="Cycle" />
            </ScrollViewer>
          </ContentControl>
        </Border>
      </Popup>
    </Grid>
    <ControlTemplate.Triggers>
      <Trigger Property="IsSuspendingPopupAnimation"
                     Value="True">
        <Setter Property="PopupAnimation"
                        TargetName="PART_Popup"
                        Value="None" />
      </Trigger>
      <Trigger Property="Icon"
                     Value="{x:Null}">
        <Setter Property="Visibility"
                        TargetName="Icon"
                        Value="Collapsed" />
      </Trigger>
      <Trigger Property="IsChecked"
                     Value="True">
        <Setter Property="Visibility"
                        TargetName="GlyphPanel"
                        Value="Visible" />
        <Setter Property="Visibility"
                        TargetName="Icon"
                        Value="Collapsed" />
      </Trigger>
      <Trigger Property="HasDropShadow"
                     SourceName="PART_Popup"
                     Value="True">
        <Setter TargetName="LayoutRoot"
                        Property="Effect">
          <Setter.Value>
            <DropShadowEffect Color="{DynamicResource MenuShadowColor}"
                                          BlurRadius="4"
                                          ShadowDepth="2"
                                          Direction="315"
                                          Opacity="0.3" />
          </Setter.Value>
        </Setter>
        <Setter TargetName="LayoutRoot"
                        Property="Padding"
                        Value="0,0,6,6" />
      </Trigger>
      <Trigger Property="IsHighlighted"
                     Value="True">
        <Setter Property="Stroke"
                        TargetName="Bg"
                        Value="{DynamicResource TopMenuItemSelectionStroke}" />
      </Trigger>
      <Trigger Property="IsKeyboardFocused"
                     Value="True">
        <Setter Property="Stroke"
                        TargetName="Bg"
                        Value="{DynamicResource TopMenuItemPressedStroke}" />
        <Setter Property="Fill"
                        TargetName="Bg"
                        Value="{DynamicResource TopMenuItemPressedFill}" />
      </Trigger>
      <Trigger Property="IsSubmenuOpen"
                     Value="True">
        <Setter Property="Stroke"
                        TargetName="Bg"
                        Value="{DynamicResource TopMenuItemPressedStroke}" />
        <Setter Property="Fill"
                        TargetName="Bg"
                        Value="{DynamicResource TopMenuItemPressedFill}" />
      </Trigger>
      <Trigger Property="IsEnabled"
                     Value="False">
        <Setter Property="Foreground"
                        Value="{DynamicResource DisabledMenuItemForeground}" />
        <Setter Property="Fill"
                        TargetName="GlyphPanel"
                        Value="{DynamicResource DisabledMenuItemGlyphPanel}" />
      </Trigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>

  <ControlTemplate x:Key="{ComponentResourceKey ResourceId=TopLevelItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}"
                     TargetType="{x:Type MenuItem}">
    <Grid SnapsToDevicePixels="True">
      <Rectangle x:Name="Bg"
                       Fill="{TemplateBinding Background}"
                       Margin="1"
                       Stroke="{TemplateBinding BorderBrush}"
                       StrokeThickness="1" />
      <DockPanel>
        <ContentPresenter x:Name="Icon"
                                  ContentSource="Icon"
                                  Margin="4,0,6,0"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                  VerticalAlignment="Center" />
        <Path x:Name="GlyphPanel"
                      Data="{StaticResource Checkmark}"
                      Fill="{DynamicResource CheckmarkFill}"
                      FlowDirection="LeftToRight"
                      Visibility="Collapsed"
                      Margin="8,0,0,0"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center" />
        <ContentPresenter ContentSource="Header"
                                  Margin="{TemplateBinding Padding}"
                                  RecognizesAccessKey="True"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
      </DockPanel>
    </Grid>
    <ControlTemplate.Triggers>
      <Trigger Property="Icon"
                     Value="{x:Null}">
        <Setter Property="Visibility"
                        TargetName="Icon"
                        Value="Collapsed" />
      </Trigger>
      <Trigger Property="IsChecked"
                     Value="True">
        <Setter Property="Visibility"
                        TargetName="GlyphPanel"
                        Value="Visible" />
        <Setter Property="Visibility"
                        TargetName="Icon"
                        Value="Collapsed" />
      </Trigger>
      <Trigger Property="IsHighlighted"
                     Value="True">
        <Setter Property="Stroke"
                        TargetName="Bg"
                        Value="{DynamicResource TopMenuItemSelectionStroke}" />
      </Trigger>
      <Trigger Property="IsKeyboardFocused"
                     Value="True">
        <Setter Property="Stroke"
                        TargetName="Bg"
                        Value="{DynamicResource TopMenuItemPressedStroke}" />
        <Setter Property="Fill"
                        TargetName="Bg"
                        Value="{DynamicResource TopMenuItemPressedFill}" />
      </Trigger>
      <Trigger Property="IsEnabled"
                     Value="False">
        <Setter Property="Foreground"
                        Value="{DynamicResource DisabledMenuItemForeground}" />
        <Setter Property="Fill"
                        TargetName="GlyphPanel"
                        Value="{DynamicResource DisabledMenuItemGlyphPanel}" />
      </Trigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>

  <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}"
                     TargetType="{x:Type MenuItem}">
    <Grid SnapsToDevicePixels="True">
      <Rectangle x:Name="Bg"
                       Fill="{TemplateBinding Background}"
                       Stroke="{TemplateBinding BorderBrush}"
                       StrokeThickness="1" />
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition MinWidth="24"
                                      SharedSizeGroup="MenuItemIconColumnGroup"
                                      Width="Auto" />
          <ColumnDefinition Width="4" />
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="6" />
          <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup"
                                      Width="Auto" />
          <ColumnDefinition Width="17" />
        </Grid.ColumnDefinitions>
        <ContentPresenter x:Name="Icon"
                                  ContentSource="Icon"
                                  Margin="1"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                  VerticalAlignment="Center" />
        <Path x:Name="GlyphPanel"
                      Data="{StaticResource Checkmark}"
                      Fill="{DynamicResource CheckmarkFill}"
                      FlowDirection="LeftToRight"
                      Visibility="Collapsed"
                      Margin="5,0,0,0"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center" />
        <ContentPresenter Grid.Column="2"
                                  ContentSource="Header"
                                  Margin="{TemplateBinding Padding}"
                                  RecognizesAccessKey="True"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
        <TextBlock Grid.Column="4"
                           Margin="{TemplateBinding Padding}"
                           Text="{TemplateBinding InputGestureText}"
                           Visibility="Collapsed" />
        <Path Grid.Column="5"
                      Data="{StaticResource RightArrow}"
                      Fill="{DynamicResource RightArrowFill}"
                      Margin="4,0,0,0"
                      VerticalAlignment="Center" />
      </Grid>
      <Popup x:Name="PART_Popup"
                   AllowsTransparency="True"
                   Focusable="False"
                   HorizontalOffset="-2"
                   IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
                   PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
                   Placement="Right"
                   VerticalOffset="-3">
        <Border x:Name="LayoutRoot"
                        Background="Transparent">
          <ContentControl x:Name="SubMenuBorder"
                                    IsTabStop="False"
                                    Template="{DynamicResource {ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}}">
            <ScrollViewer x:Name="SubMenuScrollViewer"
                                      CanContentScroll="True"
                                      Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
              <ItemsPresenter x:Name="ItemsPresenter"
                                            KeyboardNavigation.DirectionalNavigation="Cycle"
                                            Grid.IsSharedSizeScope="True"
                                            Margin="0"
                                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                            KeyboardNavigation.TabNavigation="Cycle" />
            </ScrollViewer>
          </ContentControl>
        </Border>
      </Popup>
    </Grid>
    <ControlTemplate.Triggers>
      <Trigger Property="IsSuspendingPopupAnimation"
                     Value="True">
        <Setter Property="PopupAnimation"
                        TargetName="PART_Popup"
                        Value="None" />
      </Trigger>
      <Trigger Property="Icon"
                     Value="{x:Null}">
        <Setter Property="Visibility"
                        TargetName="Icon"
                        Value="Collapsed" />
      </Trigger>
      <Trigger Property="IsChecked"
                     Value="True">
        <Setter Property="Visibility"
                        TargetName="GlyphPanel"
                        Value="Visible" />
        <Setter Property="Visibility"
                        TargetName="Icon"
                        Value="Collapsed" />
      </Trigger>
      <Trigger Property="HasDropShadow"
                     SourceName="PART_Popup"
                     Value="True">
        <Setter TargetName="LayoutRoot"
                        Property="Effect">
          <Setter.Value>
            <DropShadowEffect Color="{DynamicResource MenuShadowColor}"
                                          BlurRadius="4"
                                          ShadowDepth="2"
                                          Direction="315"
                                          Opacity="0.3" />
          </Setter.Value>
        </Setter>
        <Setter TargetName="LayoutRoot"
                        Property="Padding"
                        Value="0,0,6,6" />
      </Trigger>
      <Trigger Property="IsHighlighted"
                     Value="True">
        <Setter Property="Fill"
                        TargetName="Bg"
                        Value="{DynamicResource MenuItemSelectionFill}" />
        <Setter Property="Stroke"
                        TargetName="Bg"
                        Value="{DynamicResource MenuItemSelectionStroke}" />
      </Trigger>
      <Trigger Property="IsEnabled"
                     Value="False">
        <Setter Property="Foreground"
                        Value="{DynamicResource DisabledMenuItemForeground}" />
        <Setter Property="Fill"
                        TargetName="GlyphPanel"
                        Value="{DynamicResource DisabledMenuItemGlyphPanel}" />
      </Trigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>

  <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}"
                     TargetType="{x:Type MenuItem}">
    <Grid SnapsToDevicePixels="True">
      <Rectangle x:Name="Bg"
                       Fill="{TemplateBinding Background}"
                       Stroke="{TemplateBinding BorderBrush}"
                       StrokeThickness="1" />
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition MinWidth="24"
                                      SharedSizeGroup="MenuItemIconColumnGroup"
                                      Width="Auto" />
          <ColumnDefinition Width="4" />
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="6" />
          <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup"
                                      Width="Auto" />
          <ColumnDefinition Width="17" />
        </Grid.ColumnDefinitions>
        <ContentPresenter x:Name="Icon"
                                  ContentSource="Icon"
                                  Margin="1"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                  VerticalAlignment="Center" />
        <Path x:Name="GlyphPanel"
                      Data="{StaticResource Checkmark}"
                      Fill="{DynamicResource CheckmarkFill}"
                      FlowDirection="LeftToRight"
                      Visibility="Collapsed"
                      Margin="5,0,0,0"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center" />
        <ContentPresenter Grid.Column="2"
                                  ContentSource="Header"
                                  Margin="{TemplateBinding Padding}"
                                  RecognizesAccessKey="True"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
        <TextBlock Grid.Column="4"
                           Margin="{TemplateBinding Padding}"
                           Text="{TemplateBinding InputGestureText}" />
      </Grid>
    </Grid>
    <ControlTemplate.Triggers>
      <Trigger Property="Icon"
                     Value="{x:Null}">
        <Setter Property="Visibility"
                        TargetName="Icon"
                        Value="Collapsed" />
      </Trigger>
      <Trigger Property="IsChecked"
                     Value="True">
        <Setter Property="Visibility"
                        TargetName="GlyphPanel"
                        Value="Visible" />
        <Setter Property="Visibility"
                        TargetName="Icon"
                        Value="Collapsed" />
      </Trigger>
      <Trigger Property="IsHighlighted"
                     Value="True">
        <Setter Property="Fill"
                        TargetName="Bg"
                        Value="{DynamicResource MenuItemSelectionFill}" />
        <Setter Property="Stroke"
                        TargetName="Bg"
                        Value="{DynamicResource MenuItemSelectionStroke}" />
      </Trigger>
      <Trigger Property="IsEnabled"
                     Value="False">
        <Setter Property="Foreground"
                        Value="{DynamicResource DisabledMenuItemForeground}" />
        <Setter Property="Fill"
                        TargetName="GlyphPanel"
                        Value="{DynamicResource DisabledMenuItemGlyphPanel}" />
      </Trigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>

  <Style TargetType="ContextMenu" BasedOn="{StaticResource MetroContextMenu}" />

</ResourceDictionary>